﻿<!DOCTYPE html>
<!--隐患类别饼状图统计-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="/static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="/static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }
        </style>
    <script src="/static/js/echarts2.0.js"></script>
    <script>

    </script>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-row>
            <el-col :span="24">
                <el-form label-position="right" ref="form" :inline="true" :model="formInline" class="demo-form-inline"
                    style="margin-bottom: 15px;">
                    <el-row>
                        <el-col class="head-tool">

<div class="new_title fl"><strong><img src="/static/images/icon1.png" />隐患类别饼状图统计</strong>
                            </div>

                            <span>
                                <btn :text="col.btnSelect" imgsrc="/static/images/search.png" linetype="4"
                                    @click="onSubmit"></btn>
                            </span>
                        </el-col>
                    </el-row>
                    <el-row>


                        <!--<el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <el-input size="mini">
                                            <template slot="prepend">
                                                {{RisksManagement.RiskEChart.RiskLevel+mark.m}}
                                            </template>
                                            <el-select @visible-change="visibleChange" v-model="formInline.model.RiskLevel" slot="suffix" :placeholder="RisksManagement.RiskEChart.RiskLevel">
                                                <el-option label="请选择" value=""></el-option>
                                                <el-option v-for="item in RiskLevel" :label="item.value" :value="item.key"></el-option>
                                            </el-select>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>-->
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input size="mini">
                                        <template slot="prepend">
                                            {{RisksManagement.RiskEChart.SelectDate+'开始'+mark.m}}
                                        </template>
                                        <el-date-picker v-model="formInline.model.DiscoveryTimeStart" type="date" slot="suffix" format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
                                            size="mini" placeholder="选择日期">
                                        </el-date-picker>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input size="mini">
                                        <template slot="prepend">
                                            {{RisksManagement.RiskEChart.SelectDate+'结束'+mark.m}}
                                        </template>
                                        <el-date-picker v-model="formInline.model.DiscoveryTimeEnd" type="date" slot="suffix" format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
                                            size="mini" placeholder="选择日期">
                                        </el-date-picker>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <!-- <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input size="mini">
                                        <template slot="prepend">
                                            {{RisksManagement.RiskEChart.RiskType+mark.m}}
                                        </template>
                                        <el-select @visible-change="visibleChange" v-model="formInline.model.RiskType" slot="suffix"
                                            :placeholder="RisksManagement.RiskEChart.RiskType">
                                            <el-option label="请选择" value=""></el-option>
                                            <el-option v-for="item in RiskType" :label="item.value" :value="item.key">
                                            </el-option>
                                        </el-select>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col> -->

                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                                <div class="elst-select-mini">
                                    <el-form-item>
                                        <el-input size="mini">
                                            <template slot="prepend">
                                                {{RisksManagement.RiskEChart.RiskLevel+mark.m}}
                                            </template>
                                            <el-select @visible-change="visibleChange" v-model="formInline.model.RiskLevel" slot="suffix"
                                                :placeholder="RisksManagement.RiskEChart.RiskLevel">
                                                <el-option label="请选择" value=""></el-option>
                                                <el-option v-for="item in RiskLevel" :label="item.level" :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-input>
                                    </el-form-item>
                                </div>
                            </el-col>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                           
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input size="mini">
                                        <template slot="prepend">
                                            {{RisksManagement.RiskEChart.Department+mark.m}}
                                        </template>
                                        
                                        <treeselect v-model="formInline.model.Department" :options="Department" :flat="true" slot="suffix"
                                                    style="line-height: 28px;width:70%;float: right;" placeholder="请选择" />
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>



                    </el-row>

                </el-form>
                <div id="ChartBox" style="height:400px;margin-top:50px;"></div>

            </el-col>
        </el-row>
        <el-dialog title="Echart" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%"
            top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    id: '0',

                    mydata: null,
                    //mytree: myTree,
                    //页面内数据初始化
                    ListItem: ListItem,
                    formInline: {
                        model: {
                            type: 'RiskCategory',
                            DateBegin: '',
                            DateEnd: '',
                            RiskType: '',
                            RiskLevel: '',
                            //Department: ''
                        },
                    },
                    RiskType: [],
                    RiskLevel: [],
                    Department: [],
                    legend: [],
                    data: [],
                    title: '隐患类别饼状图',
                    subtext: '隐患类别'
                }
            },
            mounted: function () {
                //this.RiskLevel = getDicData('03');//字典内容
                tablehigh(this);//计算table高度以及el-tab-pane高度
                //this.RiskType = getDicData('100');

                //this.Department = fn(this.mytree, "0");
                this.getDepartmentData();
                this.getRiskLevel();
                //初始化数据
                this.getData();
                //获取数据
                this.mydata = {
                    title: this.title,
                    subtext: this.subtext,
                    legend: this.legend,
                    data: this.data
                };
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //getDicValue: function (row, column, cellValue, index) {
                //    if (cellValue) {
                //        if (typeof cellValue === 'string' || typeof cellValue === 'number') {
                //            return getTreeValue(this.mydata, cellValue)
                //        }
                //        else {
                //            var result = '';
                //            for (var i = 0; i < cellValue.length; i++) {
                //                result += getTreeValue(this.mydata, cellValue[i]) + ',';
                //            }
                //            result = result.substr(0, result.length - 1);
                //            return result;
                //        }
                //    }
                //},
                //初始化部门下拉树(完成)
                getDepartmentData: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.Department = menuHelper(response.data.pageData, guidEmpty)
                        //console.log('h1', response.data.pageData);
                        //console.log('h2', mythis.department);
                    }, false);
                },
                getData: function () {
                    var mythis = this
                    
                    myAjax("post", mythis, '/api/YH_StandingBookChart/GetRiskTypeChart?discoveryTimeStart=' + mythis.formInline.model.DiscoveryTimeStart + '&discoveryTimeEnd=' + mythis.formInline.model.DiscoveryTimeEnd + '&riskLevel=' + mythis.formInline.model.RiskLevel + '&department=' + mythis.formInline.model.Department, {}, function (response) {
                        //mythis.legend = response.data.legend
                        mythis.legend = [];
                        mythis.data = response.data.result
                        for (var i = 0; i < mythis.data.length;i++) {
                            mythis.legend.push(mythis.data[i].name);
                        }
                        mythis.title = response.data.title
                        mythis.subtext = response.data.subtext

                        var myChart = echarts.init(document.getElementById('ChartBox'));
                        option = {
                            title: {
                                text: mythis.title,
                                subtext: mythis.subtext,
                                x: 'center'
                            },
                            tooltip: {
                                trigger: 'item',
                                formatter: "{a} <br/>{b} : {c} ({d}%)"
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'right',
                                data: mythis.legend
                            },
                            series: [
                                {
                                    name: '',
                                    type: 'pie',
                                    radius: '55%',
                                    center: ['50%', '60%'],
                                    data: mythis.data,
                                    itemStyle: {
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        };
                        myChart.setOption(option);
                    }, false);

                },
                //初始化级别
                getRiskLevel: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/YH_Grade/GetList', { model: { }, offset: 0, limit: 100 }, function (response) {
                        mythis.RiskLevel = response.data.pageData;

                        //console.log(response.data.pageData);
                    }, false);
                },
                //获取分页数据
                GetPageData: function (currentIndex) {
                    this.getData();//GetPageData(this, currentIndex, '/api/RiskLevel/GetList')
                },
                //查询方法
                onSubmit: function () {
                    //onSubmit(this);
                    this.getData();
                },
            }
        });

        //下拉树数据格式化
        function menuHelper(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelper(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;

        }
        //var myChart = echarts.init(document.getElementById('ChartBox'));
        //option = {
        //    title: {
        //        text: app.mydata.title,
        //        subtext: app.mydata.subtext,
        //        x:'center'
        //    },
        //    tooltip: {
        //        trigger: 'item',
        //        formatter: "{a} <br/>{b} : {c} ({d}%)"
        //    },
        //    legend: {
        //        orient: 'vertical',
        //        left: 'right',
        //        data: app.mydata.legend
        //    },
        //    series: [
        //        {
        //            name: '',
        //            type: 'pie',
        //            radius: '55%',
        //            center: ['50%', '60%'],
        //            data: app.mydata.data,
        //            itemStyle: {
        //                emphasis: {
        //                    shadowBlur: 10,
        //                    shadowOffsetX: 0,
        //                    shadowColor: 'rgba(0, 0, 0, 0.5)'
        //                }
        //            }
        //        }
        //    ]
        //};
        //myChart.setOption(option);
    </script>
</body>

</html>
